package com.kanshu.client.widget.adapter.menu;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatButton;

import android.view.View;
import android.view.ViewGroup;

import com.kanshu.client.model.menu.MenuItem;
import com.kanshu.client.widget.adapter.BaseCustomAdapter;

import java.util.List;


public class MenuAdapter<T extends MenuItem> extends BaseCustomAdapter<T> {


    public MenuAdapter(@NonNull Context context, List<T> dataSource) {
        super(context, dataSource);
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {

        if (view == null) {
            view = new AppCompatButton(getContext());
        }

        AppCompatButton button = (AppCompatButton) view;

        MenuItem menuItem = getItem(position);
        button.setText(String.valueOf(position + 1).concat(".").concat(menuItem.getName()));
        button.setBackgroundResource(menuItem.getColor());
        //解决焦点冲突
        button.setClickable(false);
        button.setFocusable(false);
        button.setFocusableInTouchMode(false);
        button.setAllCaps(false);

        return button;
    }

}
